<template>
    <div>

        <el-table
                :data="list.slice((currentPage-1)*pagesize,currentPage*pagesize)"
                :default-sort = "{prop: 'date', order: 'descending'}"
                 >
            <el-table-column
                    label="日期"
                    sortable
                    prop="date">
            </el-table-column>
            <el-table-column
                    label="姓名"
                    prop="pname">
            </el-table-column>
            <el-table-column
                    label="性别"
                    align="center">
                <template #default="scope">
                    <p v-if="scope.row.sex=='1'">男</p>
                    <p v-if="scope.row.sex=='2'">女</p>
                </template>
            </el-table-column>
            <el-table-column label="操作" width="180" align="center">

                <template #default="scope">
                    <el-button v-if="scope.row.flags==0" type="text" icon="el-icon-question" @click="handleEdit(scope.$index, scope.row)">诊断
                    </el-button>
                    <el-button v-if="scope.row.flags==1" type="text" icon="el-icon-question" @click="handleEdit(scope.$index, scope.row)" disabled>已诊断
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <center>
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="currentPage"
                    :page-sizes="[5, 10, 20, 40]"
                    :page-size="pagesize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="list.length"
            >
            </el-pagination>
        </center>
    </div>
</template>

<script>
    import axios from "axios";

    export default {
        name: "PatientList",
        data(){
            return{

                patients:{
                    id: "",
                    idcard: "",
                    name: "",
                    phone: "",
                    password: "",
                    sex: 1,
                    age: 12,
                    loginName: "",
                    address: "",
                    deleted: 0,
                },
                patients:[],
                list:{
                    id: "",
                    date: "",
                    did: "",
                    pid: "",
                    pname:'',
                    sex:0,
                    flags:0,
                },
                list:[],
                id:'',
                currentPage:1, //初始页
                pagesize:10,    //    每页的数据
            }
        },
        activated(){
            this.create();
        },
        methods: {
            create(){
              this.id=localStorage.getItem("id");
                axios.post("http://119.29.60.153:8001/doctorservice/registration/getRegistrationByDId?id="+this.id).then(resp=> {
                    this.patients=resp.data.data.patients;
                    this.list=resp.data.data.list;
                    for(var i=0;i<this.list.length;i++){
                        this.list[i].pname=this.patients[i].name;
                        this.list[i].sex=this.patients[i].sex;
                    }
                })
            },
            handleSizeChange: function (size) {
                this.pagesize = size;
                console.log(this.pagesize)  //每页下拉显示数据
            },
            handleCurrentChange: function(currentPage){
                this.currentPage = currentPage;
                console.log(this.currentPage)  //点击第几页
            },

            handleEdit(index,row){
                localStorage.setItem('pid',row.pid);
                localStorage.setItem('rid',row.id);
                this.$router.push({name:'PatientInf',});
            }
        },
    }
</script>

<style scoped>

</style>